<template>
  <view>
    <u-popup
      class="resume-deliver-container"
      v-model="showPopupDialog"
      @close="handleClose"
      mode="bottom"
      width="100%"
      closeable
    >
      <view class="container">
        <view class="text1"> 完善简历，求职快人一步 </view>
        <view> </view>

        <view @click="handleUploadAttachResume" class="card-attachment-resume">
          <view class="card-attachment-resume-box1">
            附件简历 <span class="recomment"> 推荐 </span>
          </view>
          <view class="card-attachment-resume-text2">
            点击上传简历文件，直接投递岗位
          </view>
        </view>

        <view class="card-online-resume" @click="handleCompleteOnlineResume">
          <view class="card-online-resume-box1">
            <view class="online-text"> 在线简历</view>
            <view class="defect-text"> 缺少“教育背景”、“工作经历” </view>
          </view>
          <view class="complete"> 去完善 </view>
        </view>
      </view>
    </u-popup>
  </view>
</template>
  <script>
import { uploadAction, uploadBaseUrl, checkPersonCompleteNew } from "@/api/index";
import { personAddAttachment } from '@/api/modules/resumeCreate';

export default {
  props: {
    isShowPop: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      uploadAttachFileImg:
        "https://img3.job1001.com/ypMp/elan/images/resume/img_upload_attach_resume2.png",
      // 附件简历列表
      attachmentFileList: [],
      // 在线简历是否已经完善
      isOnlineResumeComplete: false,
      showPopupDialog: false,

      companyId: undefined,
      positionId: undefined,
      jobName: undefined,
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
    };
  },
  methods: {
    // 简历完善度校验
    checkPersonResume() {
      if (!this.personId) {
        return;
      }
      uni.showLoading({
        title: "请等待",
        mask: false,
      });
      var params = {
        person_id: this.personId,
      };
      checkPersonCompleteNew(params)
        .then((res) => {
          uni.hideLoading();
          if (res.code == 200) {
            if (res.data.isHaveAttachList==2 && res.data.isOnlineComplete == 2) {
              this.showPopupDialog = true;
            }
          } else {
            uni.showToast({
              icon: 'none',
              title: res.status_desc
            });
          }
        })
        .catch((err) => {
          uni.hideLoading();
        });
    },

    getCurrentPersonId() {
      return uni.getStorageSync("person-id").slice(2) || undefined;
    },

    // 点击 跳转到 上传附件简历页面
    handleUploadAttachResume() {
      this.personId = this.getCurrentPersonId();
      if (!this.personId) {
        this.$emit("showLoginDialog");
        return;
      }
      this.handleUpload();
    },

    // 点击完善在线简历
    handleCompleteOnlineResume() {
      this.personId = this.getCurrentPersonId();
      if (!this.personId) {
        this.$emit("showLoginDialog");
        return;
      }
      this.handleClose();
      uni.navigateTo({
        url: "/pagesSub/newResume/index",
      });
    },

    setVisibility(visibility) {
      this.showPopupDialog = visibility;
    },

    handleClose() {
      this.showPopupDialog = false;
    },

    closeDialog() {
      this.showPopupDialog = false;
    },
    handleUpload() {
      let uploadApi = '';
      // #ifdef H5
      uploadApi = uni.chooseFile;
      // #endif
      // #ifdef MP-WEIXIN

      uploadApi = wx.chooseMessageFile;
      // #endif
      const TYPE = ['.doc', '.docx', '.pdf'];
      uploadApi({
        count: 1, //默认100
        extension: TYPE,
        success: (res) => {
          let tempFilePaths = res.tempFiles;
          let fileExt = '.' + tempFilePaths[0].name.replace(/.+\./, '');
          if (TYPE.indexOf(fileExt) < 0) {
            return uni.showToast({
              icon: 'none',
              title: '请选择pdf类型文件'
            });
          }
          if (tempFilePaths[0].size / (1024 * 1024) > 10) {
            return uni.showToast({
              icon: 'none',
              title: '文件大小不能超过10M'
            });
          }
          uni.showLoading({
            title: '正在上传'
          });
          uni.uploadFile({
            url: uploadAction,
            filePath: tempFilePaths[0].path,
            name: 'file',
            success: (uploadRes) => {
              let param = {
                personId: this.personId,
                attUrl: uploadBaseUrl + uploadRes.data,
                attName: tempFilePaths[0].name
              };
              personAddAttachment(param).then((fujianRes) => {
                uni.hideLoading();
                if (fujianRes.code === 200) {
                  uni.showToast({
                    icon: 'none',
                    title: '上传成功'
                  });
                  this.$emit('uploaded');
                  this.handleClose();
                }
              });
            }
          });
        }
      });
    }
  },
};
</script>
  <style lang="scss" scoped>
.resume-deliver-container {
  .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-left: 40rpx;
    padding-right: 32rpx;
    padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(20rpx + env(safe-area-inset-bottom));

    .text1 {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 28rpx 0;
      font-size: 32rpx;
      color: #333333;
    }

    .card-attachment-resume {
      display: flex;
      flex-direction: column;
      margin-bottom: 24rpx;
      padding: 40rpx 32rpx;
      width: 100%;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;

      &-box1 {
        width: 100%;
        display: flex;
        flex-direction: row;
        font-weight: 500;
        font-size: 32rpx;
        color: #222222;

        .recomment {
          display: flex;
          justify-content: center;
          align-items: center;
          margin-left: 24rpx;
          width: 84rpx;
          height: 40rpx;
          font-size: 26rpx;
          color: #f04646;
          background: #ffeeee;
          border-radius: 8rpx;
        }
      }

      &-text2 {
        margin-top: 8rpx;
        font-size: 24rpx;
        color: #999999;
      }
    }

    .card-online-resume {
      width: 100%;
      display: flex;
      align-items: center;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;
      padding-left: 32rpx;
      padding-right: 32rpx;
      padding-top: 40rpx;
      padding-bottom: 40rpx;

      &-box1 {
        flex: 1;

        .online-text {
          font-weight: 500;
          font-size: 32rpx;
          color: #222222;
        }

        .defect-text {
          margin-top: 8rpx;
          font-size: 24rpx;
          color: #999999;
        }
      }

      .complete {
        width: 148rpx;
        height: 60rpx;
        background: #ffffff;
        border-radius: 8rpx;
        border: 2rpx solid #f04646;
        font-weight: 400;
        font-size: 28rpx;
        color: #f04646;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
      }
    }
    .online-resume-uncomplete-box {
      font-weight: 400;
      font-size: 24rpx;
      color: #999999;
      width: 100%;
      padding-bottom: 40rpx;
      .edit-online-resume {
        color: #f04646;
        margin-bottom: 40rpx;
      }
    }
  }
}
</style>
  